//
//  HomeViewController.m
//  E-learning
//
//  Created by MinwenYi on 14-7-1.
//  Copyright (c) 2014年 Yang. All rights reserved.
//

#import "HomeViewController.h"

@interface HomeViewController ()

@end

@implementation HomeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    _section2ContentData = [[NSMutableArray alloc] initWithObjects:@"课程中心",@"学习记录",@"我的收藏",@"我的下载", nil];
    _section3ContentData = [[NSMutableArray alloc] initWithObjects:@"用户反馈", nil];
    _myTable = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    _myTable.delegate = self;
    _myTable.dataSource = self;
    [self.view addSubview:_myTable];
    self.myTable.backgroundColor = [UIColor colorWithRed:244/255.0 green:240/255.0 blue:237/255.0 alpha:1];
    
    
    UIView *v = [[UIView alloc] initWithFrame:CGRectZero];
    [self.myTable setTableFooterView:v];
    
    if ([_myTable respondsToSelector:@selector(setSeparatorInset:)]) {
        [_myTable setSeparatorInset:UIEdgeInsetsZero];
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

{
    UIView *section1View = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 55, 320)];
    section1View.backgroundColor = [UIColor colorWithRed:218/255.0 green:218/255.0 blue:218/255.0 alpha:1];
    UILabel *section1Label = [[UILabel alloc] initWithFrame:CGRectMake(15, 18, 85,30)];
    section1Label.textColor = [UIColor colorWithRed:112/255.0 green:112/255.0 blue:112/255.0 alpha:1];
    section1Label.text = @"百度微课";
    
    [section1View addSubview:section1Label];

    UIView *section2View = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 320)];
    section2View.backgroundColor = [UIColor colorWithRed:233/255.0 green:232/255.0 blue:227/255.0 alpha:1];
    switch (section) {
        case 0:
            return section1View;
            break;
        case 1:
            return section2View;
            break;
        case 2:
            return section2View;
            break;
        default:
            return section1View;
            break;
    }



}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - tableView delegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

{
    switch (section) {
        case 0:
            return @"百度微课";
            break;
        case 1:
            return @"";
            break;
        case 2:
            return @"";
            break;
        default:
            return @"";
            break;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    switch (section) {
        case 0:
            return 55;
            break;
        case 1:
            return 15;
            break;
        case 2:
            return 15;
            break;
        default:
            return 15;
            break;
    }

}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{
    switch (section) {
        case 0:
            return 2;
            break;
       case 1:
            return _section2ContentData.count;
            break;
        case 2:
            return _section3ContentData.count;
            break;
        default:
            return 0;
            break;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifer = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifer];
        cell.backgroundColor = [UIColor colorWithRed:244/255.0 green:240/255.0 blue:237/255.0 alpha:1];
    }
    
    switch (indexPath.section) {
        case 0:
            cell.textLabel.text = @"";
            break;
        case 1:
            cell.textLabel.text = [_section2ContentData objectAtIndex:indexPath.row];
            break;
        case 2:
            cell.textLabel.text = [_section3ContentData objectAtIndex:indexPath.row];
            break;
        default:
            cell.textLabel.text = @"";
            break;
    }
//    if (cell.textLabel.text == nil || cell.textLabel.text == NULL) {
//        self.myTable.separatorStyle = UITableViewCellSeparatorStyleNone;
//    }else{
//        self.myTable.separatorStyle = UITableViewCellStyleDefault;
//    }
    return cell;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
